﻿using Flow.Manage.Contracts;
using Framework.Cache;
using Framework.Models.Entities;
using Framework.Models.Request;
using Microsoft.AspNetCore.Mvc;

namespace ApprovalFlow.Api.Controllers
{
    [ApiController]
    public class AccountController : ControllerBase
    {
        private readonly ILogger<AccountController> _logger;

        private readonly IServiceProvider _provider;

        public AccountController(ILogger<AccountController> logger, IServiceProvider provider)
        {
            _logger = logger;
            _provider = provider;
        }

        private IAccountContract _accountContract => GlobalConfig.ServiceProvider.GetRequiredService<IAccountContract>();

        [HttpPost]
        [Route("api/AdminLogin")]
        public IActionResult AdminLogin([FromBody] AdminRequest request)
        {
            var result = _accountContract.AdminLogin(request);
            if (result.success)
            {
                CacheFactory.Cache.Set(CacheKay.SessionUser, result.data); 
            }

            var aaa=  CacheFactory.Cache.Get<Biz_User>(CacheKay.SessionUser);
            return Ok(result);
        }
    }
}